package com.example.service;

import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

import android.content.Context;

public class fileService {
    private Context context;
	public fileService(Context context){
		this.context=context;
	}
	
	public void saveFile(String fileName,String fileContext) throws Exception{
		FileOutputStream outputStream = context.openFileOutput(fileName, Context.MODE_PRIVATE);
		outputStream.write(fileContext.getBytes());
		outputStream.close();
	}

	public String readFile(String fileNameText) throws IOException {
		FileInputStream stream = context.openFileInput(fileNameText);
		ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
		
		byte[] buffer = new byte[1024];
		int len = 0;
		while((len=stream.read(buffer))!=-1){
			outputStream.write(buffer, 0, len);
		}
		String context = outputStream.toString();
		outputStream.close();
		return context;
	}
}
